// pages/index/work/work.js
const http = require('../../../utils/http.js'); //相对路径
Page({
  /**
   * 页面的初始数据
   */
  data: {
    pageName: 1,
    nav2index: 0,
    nav3index: 0,
    infoList:'',//数组数据
    professionCateData:'',//业务分类数据
    navindex: '',//业务分类ID
    workId:'',
    workNumber:'',
    PageNum: 1,
    dataShow:false,
    cateDataid: '',
    total:'',
    id: ''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      pageName: options.name
    })
  },
  onShow() {
    this.getData('')
  },
  // 获取工单列表数据
  getData(){
    http.postRequest('/mini/v1/work/list', {
      status:this.data.pageName,
      per_page: '',
      page: this.data.PageNum,
      profession_cate_id: this.data.id
    }, res => {
      res.data.profession_cate_data.unshift({id: '',name: '全部'});
      for(var i in res.data.data){
        res.data.data[i].enter_time= http.transTime(res.data.data[i].enter_time) != 'NaN-NaN-NaN NaN:NaN' ? http.transTime(res.data.data[i].enter_time) : ''
      }
      this.setData({
        infoList:[...this.data.infoList,...res.data.data],
        professionCateData:res.data.profession_cate_data,
        PageNum:this.data.PageNum+1,
        total:res.data.total,
        worklisrData: res.data
      })
    })
  },
  navindex(e) {
    let index = e.currentTarget.dataset.index;
    this.setData({
      navindex: index,
      PageNum:1,
      infoList:[],
      id: e.currentTarget.dataset.cateid
    })
    this.getData()
  },
  navbind(e) {
    let index = e.currentTarget.dataset.index;
    this.setData({
      pageName: index,
      PageNum:1,
      infoList:[]
    })
    this.getData() // 查询方法
  },
  gopage(e) {
    let id=e.currentTarget.dataset.id
    this.setData({
      workId:this.data.infoList[id].id,
      workNumber:this.data.infoList[id].work_number
    })
    wx.navigateTo({
      url: '/pages/index/work/detail?workId='+this.data.workId+'&workNumber='+this.data.workNumber
    })
  },
  nav2index(e){
    let index = e.currentTarget.dataset.index;
    this.setData({
      nav2index: index
    })
  },
  nav3index(e){
    let index = e.currentTarget.dataset.index;
    this.setData({
      nav3index: index
    })
  },
  jump(){
    wx.navigateTo({
      url: '/pages/openOrder/repair/repair',
    })

  },

  onReachBottom: function () {
    if(this.data.PageNum <= this.data.worklisrData.last_page){
      this.getData() // 查询方法
    }
  },
})